import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:village_android/utils/common_utils.dart';


class CountWidget extends StatefulWidget {

  int count = 0;
  int value = 0;
  final String targetId;
  final ValueCallback callBack;

  CountWidget({Key key, this.count,this.value, this.targetId, this.callBack})
      : super(key: key);

  @override
  _CountWidgetState createState() => _CountWidgetState();
}

class _CountWidgetState extends State<CountWidget> {

  @override
  Widget build(BuildContext context) {
    return Container(
      width: ScreenUtil.getInstance().setWidth(180),
      height: ScreenUtil.getInstance().setHeight(80),
      child:Container(
        decoration: ShapeDecoration(
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(2.0)),
              side: BorderSide(color: Colors.black54)),
        ),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[


            // 减值操作，数量为 1 停止
            Expanded(
              child: InkWell(
                onTap: widget.count == 0 ? null : (() {
                  widget.callBack(widget.targetId, false);
                  setState(() {
                    widget.count --;
                  });
                }),
                child: DecoratedBox(
                    decoration: BoxDecoration(
                      border: Border(
                          right: BorderSide(color: Colors.black54, width: 1.0)),
                    ),
                    child: Center(child: Text('－',
                        style: TextStyle(fontSize: 16.0, color: Colors.black)))),
              ),
            ),
            Expanded(child: Center(child: Text(
                widget.count.toString(), style: TextStyle(fontSize: 14.0, color: Colors.black))),
                flex: 2),
            // 加值操作
            Expanded(
              child: InkWell(
                onTap: (() {
                  widget.callBack(widget.targetId, true);
                  setState(() {
                    widget.count ++;
                  });
                }),
                child: DecoratedBox(
                    decoration: BoxDecoration(
                      border: Border(
                          left: BorderSide(color: Colors.black54, width: 1.0)),
                    ),
                    child: Center(child: Text('＋',
                        style: TextStyle(fontSize: 16.0, color: Colors.black)))),
              ),
            )
          ],
        ),
      ),
      

    );
  }
}
